#include <iostream>

#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"


class OneLoop {
public:
    //标记数字是否已经被选过
    std::vector<char> tag;
    int take_cnt = 0;
//    int first_size=0;
//    int second_size=0;
//    int third_size=0;
    int first_n = 0;
    int second_n = 0;
    int third_n = 0;

    int target = 0;

    int res_cnt = 0;

    void first() {
        for (int i = 1; i < 10; i++) {
            if (!tag[i]) {
                tag[i] = 1;
                first_n *= 10;
                first_n += i;
                take_cnt++;
                if(first_n<target){
                    first();
                    second();
                }
                first_n -= i;
                first_n /= 10;
                take_cnt--;
                tag[i] = 0;
            }
        }
    }
    int third_tar=0;
    void second() {
        if (take_cnt == 9) {
            return;
        }
        for (int i = 1; i < 10; i++) {
            if (!tag[i]) {
                tag[i] = 1;
                second_n *= 10;
                second_n += i;
                take_cnt++;

                second();
                if(second_n%(target-first_n)==0){
                    third_tar=second_n/(target-first_n);
                    third();
                }

                second_n -= i;
                second_n /= 10;
                take_cnt--;
                tag[i] = 0;
            }
        }
    }

    void third() {
        if (take_cnt==9&&third_n==third_tar) {
//            printf("%d %d %d\n",first_n,second_n,third_n);
            res_cnt++;
        }
        for (int i = 1; i < 10; i++) {
            if (!tag[i]) {
                tag[i] = 1;
                third_n *= 10;
                third_n += i;
                take_cnt++;
                third();

                third_n -= i;
                third_n /= 10;
                take_cnt--;
                tag[i] = 0;
            }
        }
    }

    bool run(
            int a
    ) {
        tag.resize(10);
        target = a;

        first();

        printf("%d\n",this->res_cnt);

        return true;
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int a, b, c, d, e;
        //        std::cin >> a;
//        std::string s1,s2;
//        while (1){
        while (std::cin >> a) {
//            std::getline(std::cin,s2);
            OneLoop l;
            if (!l.run(a)) {
//                                return;
            }
        }


    }
};

int main() {

    //    bool cur_num= true;
    Solution().run();
    return 0;
}

